<template>
    <div>
        <div class="header">
            {{couponSource.title}}
        </div>
        <img
            class="img"
            :src="couponSource.content_image"
        >
        <div class="headline">{{couponSource.desc}}</div>
        <div class="money">
            <span>￥{{couponSource.fee}}</span>
            <span>市场价{{couponSource.o_price}}</span>
        </div>
        <div class="title">使用条件</div>
        <div
            class="condition"
            v-html="couponSource.use_desc"
        ></div>
        <div class="title">商家信息</div>
        <div class="address">
            <div>商家地址:</div>
            <div>{{couponSource.addr}}</div>
        </div>
        <div class="introduce">
            <span>商家简介:</span>
            <span>{{couponSource.company_desc}}</span>
        </div>
        <div class="introduce">
            <span>商家展示:</span>
            <span></span>
        </div>
        <div
            class="company_content"
            v-html="couponSource.company_content"
        ></div>
        <div style="height:60px;"></div>
        <div class="botton">
            <div
                class="botton-left"
                @click="goHome"
            >
                <img
                    class="botton-home"
                    src="../../asset/icon/coupon_home.png"
                />
                <span>首页</span>
            </div>
            <a
                class="botton-left"
                :href="'tel:'+couponSource.company_mobile"
            >
                <img
                    class="botton-phone"
                    src="../../asset/icon/coupon_phone.png"
                />
                <span>联系商家</span>
            </a>
            <router-link
                class="botton-right"
                :to="{path:'/couponShare',query:{id: couponSource.id}}"
            >
                <p>分享海报</p>
                <p v-if="couponSource.vip_level ==2">合伙人立赚￥{{couponSource.vip_commission_money}}</p>
            </router-link>
            <router-link
                class="botton-right"
                :to="{path:'/couponPay',query:{coupon_id: couponSource.id}}"
            >
                <p>立即抢购</p>
                <p v-if="couponSource.vip_level > 0">会员立省￥{{couponSource.return_money}}</p>
            </router-link>
        </div>
    </div>
</template>
<script>
import goodsShare from '../../config/goodsShare.js';
export default {
    name: "couponCont",
    data() {
        return {
            couponSource: {}
        };
    },
    methods: {
        // 方法
        goHome() {
            this.$router.replace({
                path: '/coupon'
            })
        },
        getCouponInfo() {
            let params = {
                id: this.$route.query.coupon_id
            };
            this.$post("/coupon/get_detaile", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.couponSource = res.data
                    }
                })
                .catch(err => { });
        },
        getCouponConfig() {
            let params = {
                coupon_id: this.$route.query.coupon_id,
            };
            this.$post("/index/wx_share", params)
                .then(res => {
                    if (res.code == 20000) {
                        res.data.url = 'http://wangzhuan.3todo.cn/?share_id=' + localStorage.getItem('token') + '&coupon_id=' + this.$route.query.coupon_id + '&from=123';
                        this.couponConfigSource = res.data
                        this.getShareConfig()
                    }
                })
        },
        getShareConfig() {
            let params = {
                // url: location.href.split('#')[0],
                url: 'http://wangzhuan.3todo.cn/',
            };
            this.$post("/index/share", params)
                .then(res => {
                    if (res.code === 20000) {
                        goodsShare(res.data, this.couponConfigSource, this.couponShareSuccess)
                    }
                })

        },
        couponShareSuccess() {
            this.$dialog.toast({ mes: '分享成功', timeout: 1000 });
        }
    },
    mounted() {
        let that = this;
        // 添加返回事件监听
        if (this.$route.query.shareType == 'coupon') {
            var state = {
                title: "",
                url: "#/coupon" // 这个url可以随便填，只是为了不让浏览器显示的url地址发生变化，对页面其实无影响
            };
            window.history.pushState(state, state.title, state.url);
            window.addEventListener("popstate", function (e) {
                that.$router.replace({
                    path: '/coupon'
                })
            }, false);
        }

    },
    beforeCreate() {
        document.querySelector("body").setAttribute("style", "background-color:#f0effe");
    },
    created() {
        // 实例创建完成
        this.getCouponInfo();
        this.getShareConfig();
        this.getCouponConfig()

    },
};
</script>
<style lang="less" >
.company_content {
    box-sizing: border-box;
    padding: 0 15px 10px;

    img {
        width: 100% !important;
    }
}
</style>
<style lang="less" scoped>
@import url("../../asset/css/couponCont");
</style>